package org.mclll.xwangplugin.town.database.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.mclll.xwangplugin.town.enums.TownLevel;
import org.mclll.xwangplugin.town.enums.TownParty;

import java.time.LocalDateTime;

/**
 * @author: geduo
 * @date: 2023/9/22 15:42
 */
@Data
@ToString
public class TownDO {
    /**
     * 城镇uuid(创建城镇时自动生成)
     */
    private String uuid;
    /**
     * 城镇名称
     */
    private String name;
    /**
     * 镇长玩家uuid
     */
    private String leaderUuid;
    /**
     * res领地名列表(json的string数组)
     */
    private String resList;
    /**
     * 城镇等级
     */
    private TownLevel townLevel;
    /**
     * 城镇阵营
     */
    private TownParty townParty;
    /**
     * 本月税收(心之石数量)
     */
    private Integer monthTax;
    /**
     * 本月税收(心之石数量)
     */
    private Integer totalTax;
    /**
     * 上次结算税收时间
     */
    private LocalDateTime lastTaxTime;
    /**
     * 镇民签到，镇长暂存心之石数量
     */
    private Double saveHartStone;
    /**
     * 上次镇长领取补贴时间
     */
    private LocalDateTime leaderLastSubsidyTime;
    /**
     * 星门json
     */
    private String starDoorJson;
    /**
     * 删除标记
     */
    private Boolean isDelete;

    public StarDoor getStarDoor() {
        return new StarDoor(starDoorJson);
    }
    @Data
    @NoArgsConstructor
    public static class StarDoor {
        private String title;
        private String pos;
//        private Material type;
        private String type;
        private String desc;

        public StarDoor(String json) {
            JSONObject jsonObj = JSON.parseObject(json);
            this.title = jsonObj.getString("title");
            this.pos = jsonObj.getString("pos");
//            this.type = Material.valueOf(jsonObj.getString("type"));
            this.type = jsonObj.getString("type");
            this.desc = jsonObj.getString("desc");
        }
    }
}
